<template>
    <div class="container">
      <el-card class="box-card">
        <!-- 标题 -->
        <div slot="header" class="clearfix">
          <h2>管理员后台登录</h2>
        </div>
        <!-- 登录表单 -->
        <el-form ref="form" :rules="rules" :model="form">
          <el-form-item prop="username">
            <el-input
              placeholder="请输入账号"
              prefix-icon="iconfont icon-zhanghao"
              v-model="form.username">
            </el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              placeholder="请输入密码"
              prefix-icon="iconfont icon-mima"
              v-model="form.password">
            </el-input>
          </el-form-item>
          <el-form-item prop="CAPTCHA" class="CAPTCHA">
            <el-input v-model="form.CAPTCHA" style="width:26%" placeholder="请输入验证码"></el-input>
            <img src="https://cdn7.axureshop.com/demo/2093544/images/%E7%99%BB%E5%BD%95%E9%A1%B5%E9%9D%A2/u2042.png" alt="" title="点击切换">
          </el-form-item>
          <div class="sevepassword">
            <el-checkbox v-model="form.sevepassword">记住密码</el-checkbox>
          </div>
          <el-button native-type="submit" type="primary" class="login-btn" @click.prevent="login">登录</el-button>
        </el-form>
      </el-card>
    </div>
</template>

<script>
export default {
  name: '',
  data() {
    return {
      form: {
        username: '',
        password: '',
        CAPTCHA: '',
        sevepassword: '',
      },
      rules: {
        username: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        CAPTCHA: [{ required: true, message: '请输入验证码', trigger: 'blur' }],
      },
    };
  },
  methods: {
    async login() {
      await this.$refs.form.validate();
      await this.$store.dispatch('user/login', this.form);
    },
  },
};
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100vh;
  background-color: skyblue;
}

.box-card {
  width: 36%;
  margin-top: 120px;
}

::v-deep .el-card__body {
  padding: 20px 40px;
}

::v-deep .el-card__header {
  padding: 10px;
}

.clearfix h2 {
  text-align: center;
  font-weight: 400;
}

.el-input + .el-input {
  margin-top: 20px;
}

::v-deep .CAPTCHA .el-form-item__content {
  display: flex;
  align-items: center;
}

.CAPTCHA img {
  height: 35px;
  margin-left: 10px;
}

.sevepassword {
  margin: 15px 0 30px;
}

::v-deep .login-btn {
  width: 100%;
  margin-bottom: 20px;
}
</style>
